package Game;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Funkcja rozpoczynajaca gre 
 * @author yoman
 *
 */
public class Core {
	public static Position[][] BATTLEFIELD;
	static List <Ant> antsBlack;
	static List <Ant> antsYellow;
	static List <Ant> antsGreen;
	static List <Ant> antsRed;
	int maxX = Settings.WIDTH/Settings.ANT_SIZE;
	int maxY = Settings.HEIGHT/Settings.ANT_SIZE;
	public static int gameAge = 0;
	public Core() {
		Core.antsBlack =  Collections.synchronizedList(new ArrayList<Ant>());
		Core.antsYellow =  Collections.synchronizedList(new ArrayList<Ant>());
		Core.antsGreen = Collections.synchronizedList(new ArrayList<Ant>());
		Core.antsRed = Collections.synchronizedList(new ArrayList<Ant>());
		Core.BATTLEFIELD = new Position[maxX][maxY];
		init();
		showPosition();
		ArtificalLife al = new ArtificalLife();
		al.start();
	}
	
	public void init() {
		System.out.println("MaxX" + maxX);
		System.out.println("MaxY" + maxY);
		for(int x=0;x<maxX;x++) {
			for(int y=0;y<maxY;y++) {

				BATTLEFIELD[x][y] = new Position(x,y);
			} 
		} 
		
		for(int i=0; i<Settings.START_AMOUNT_ANT; i++) {
			Ant black = new Ant(Species.BLACK);
			BATTLEFIELD[black.getX()][black.getY()].setAnt(black);
			antsBlack.add(black);
			
			Ant yellow = new Ant(Species.YELLOW);
			BATTLEFIELD[yellow.getX()][yellow.getY()].setAnt(yellow);
			antsYellow.add(yellow);
			
			Ant green = new Ant(Species.GREEN);
			BATTLEFIELD[green.getX()][green.getY()].setAnt(green);
			antsGreen.add(green);
			
			Ant red = new Ant(Species.RED);
			BATTLEFIELD[red.getX()][red.getY()].setAnt(red);
			antsRed.add(red);
			
			
		}
	}
	
	public void showPosition() {
		for(int x=0;x<maxX;x++) {
			for(int y=0;y<maxY;y++) {
				if(!BATTLEFIELD[x][y].isBlank()) {
					Ant ant = BATTLEFIELD[x][y].getAnt();
					System.out.println("Species:"+ ant.getSpecies());
					System.out.println("x:"+ ant.getX());
					System.out.println("y:"+ ant.getY());
				}
			} 
		} 
	}
	
	public static Position[][] getBATTLEFIELD() {
		return BATTLEFIELD;
	}

	public static List<Ant> getAntsBlack() {
		return antsBlack;
	}

	public static List<Ant> getAntsYellow() {
		return antsYellow;
	}

	public static List<Ant> getAntsGreen() {
		return antsGreen;
	}

	public static List<Ant> getAntsRed() {
		return antsRed;
	}
	
	public static int getAmountBlack() {
		return antsBlack.size();
	}
	
	public static int getAmountYellow() {
		return antsYellow.size();
	}
	
	public static int getAmountGreen() {
		return antsGreen.size();
	}
	
	public static int getAmountRed() {
		return antsRed.size();
	}	
	
	public static int getGameAge() {
		return Core.gameAge;
	}
	
	public static void increaseGameAge(){
		Core.gameAge++;
	}
}
